package com.ruoyi.demo2.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.demo2.domain.Packages;
import com.ruoyi.demo2.service.IPackagesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 货物管理Controller
 * 
 * @author ruoyi
 * @date 2024-06-18
 */
@RestController
@RequestMapping("/demo2/packages")
public class PackagesController extends BaseController
{
    @Autowired
    private IPackagesService packagesService;

    /**
     * 查询货物管理列表
     */
    @PreAuthorize("@ss.hasPermi('demo2:packages:list')")
    @GetMapping("/list")
    public TableDataInfo list(Packages packages)
    {
        startPage();
        List<Packages> list = packagesService.selectPackagesList(packages);
        return getDataTable(list);
    }

    /**
     * 导出货物管理列表
     */
    @PreAuthorize("@ss.hasPermi('demo2:packages:export')")
    @Log(title = "货物管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Packages packages)
    {
        List<Packages> list = packagesService.selectPackagesList(packages);
        ExcelUtil<Packages> util = new ExcelUtil<Packages>(Packages.class);
        util.exportExcel(response, list, "货物管理数据");
    }

    /**
     * 获取货物管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('demo2:packages:query')")
    @GetMapping(value = "/{packagesId}")
    public AjaxResult getInfo(@PathVariable("packagesId") Long packagesId)
    {
        return success(packagesService.selectPackagesByPackagesId(packagesId));
    }

    /**
     * 新增货物管理
     */
    @PreAuthorize("@ss.hasPermi('demo2:packages:add')")
    @Log(title = "货物管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Packages packages)
    {
        return toAjax(packagesService.insertPackages(packages));
    }

    /**
     * 修改货物管理
     */
    @PreAuthorize("@ss.hasPermi('demo2:packages:edit')")
    @Log(title = "货物管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Packages packages)
    {
        return toAjax(packagesService.updatePackages(packages));
    }

    /**
     * 删除货物管理
     */
    @PreAuthorize("@ss.hasPermi('demo2:packages:remove')")
    @Log(title = "货物管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{packagesIds}")
    public AjaxResult remove(@PathVariable Long[] packagesIds)
    {
        return toAjax(packagesService.deletePackagesByPackagesIds(packagesIds));
    }
}
